package edu.famework.demoZ1.answer;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

public class Manager {
    public void writeFile(List<Student> list) {
        FileWriter fw = null;
        BufferedWriter bw = null;
        try {
            fw = new FileWriter("student.txt");
            bw = new BufferedWriter(fw);
            //遍历List集合
            Iterator<Student> it = list.iterator();
            while (it.hasNext()) {
                Student stu = it.next();
                String str = stu.getSid() + " " + stu.getName() + " " + stu.getPassword() + " " + stu.getAge() + " " + stu.getAddress();
                //向目标文件写数据
                bw.write(str);
                //换行
                bw.newLine();
//              bw.flush();
            }
            //关闭资源
            bw.close(); //注意：顺序，先关闭处理流
            fw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


//    public void writeFile(List<Student> list) {
//        try {
//            FileWriter fw = new FileWriter("student.txt");
//            BufferedWriter bw = new BufferedWriter(fw);
//            //遍历List集合
//            Iterator<Student> it = list.iterator();
//            while (it.hasNext()) {
//                Student stu = it.next();
//                String str = stu.getSid() + " " + stu.getName() + " " + stu.getPassword() + " " + stu.getAge() + " " + stu.getAddress();
//                //向目标文件写数据
//                bw.write(str);
//                //换行
//                bw.newLine();
//            }
//            //关闭资源
//            bw.close(); //注意：顺序，先关闭处理流
//            fw.close();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }


